
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Article table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LocalId nvarchar (20)  = null ,

	@Title nvarchar (200)  = null ,

	@Alias varchar (200)  = null ,

	@Summary nvarchar (500)  = null ,

	@Description ntext   = null ,

	@ArticleType varchar (20)  = null ,

	@Thumbnail varchar (200)  = null ,

	@IsPublished bit   = null ,

	@OrderIndex int   = null ,

	@IsAllowDelete bit   = null ,

	@PublishedDate datetime   = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Summary]
	, [Description]
	, [ArticleType]
	, [Thumbnail]
	, [IsPublished]
	, [OrderIndex]
	, [IsAllowDelete]
	, [PublishedDate]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Article]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LocalId] = @LocalId OR @LocalId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Alias] = @Alias OR @Alias IS NULL)
	AND ([Summary] = @Summary OR @Summary IS NULL)
	AND ([ArticleType] = @ArticleType OR @ArticleType IS NULL)
	AND ([Thumbnail] = @Thumbnail OR @Thumbnail IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsAllowDelete] = @IsAllowDelete OR @IsAllowDelete IS NULL)
	AND ([PublishedDate] = @PublishedDate OR @PublishedDate IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Summary]
	, [Description]
	, [ArticleType]
	, [Thumbnail]
	, [IsPublished]
	, [OrderIndex]
	, [IsAllowDelete]
	, [PublishedDate]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Article]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LocalId] = @LocalId AND @LocalId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Alias] = @Alias AND @Alias is not null)
	OR ([Summary] = @Summary AND @Summary is not null)
	OR ([ArticleType] = @ArticleType AND @ArticleType is not null)
	OR ([Thumbnail] = @Thumbnail AND @Thumbnail is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsAllowDelete] = @IsAllowDelete AND @IsAllowDelete is not null)
	OR ([PublishedDate] = @PublishedDate AND @PublishedDate is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
